<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>积分设置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{{asset('/layuiadmin/layui/css/layui.css')}}" media="all">
    <link rel="stylesheet" href="{{asset('/layuiadmin/style/admin.css')}}" media="all">
    <style>
        .img{width:130px;height:90px;overflow: hidden;}
        .img img{width:100%;height:100%;}
        .layui-layer-nobg{width: none !important;}
        /*.layui-layer-content{width:600px;height:550px;}*/
        .layui-card-header{width:200px;text-align: left;cursor: pointer;}
        .layui-card-body{margin-left:28px;}
        .layui-upload-img{width: 120px; height: 120px; /*margin: 0 10px 10px 0;*/}

        .up{position: relative;display: inline-block;cursor: pointer;border-color: #1ab394; color: #FFF;width: auto !important;font-size: 10px !important;text-align: center !important;}
        .up input{position: absolute;top:0;left: 0;display: block;opacity: .01;width: 100px;height:30px;}
        .layui-upload-list{width: 120px;height:120px;overflow: hidden;margin: 10px auto;}
        input::-webkit-outer-spin-button,
        input::-webkit-inner-spin-button {-webkit-appearance: none !important;margin: 0;}
       
    </style>
</head>
<body>

<div class="layui-fluid">
    
    <div class="layui-card"style="margin-top:50px">
      <div class="layui-card-header">设置支付密码</div>
      <div class="layui-card-body layui-row layui-col-space10">
        <div class="layui-form">

            <div class="layui-form-item">
                <label class="layui-form-label">输入手机号</label>
                <div class="layui-input-block">
                    <input type="number" name="schoolname" lay-verify="schoolname" autocomplete="off" placeholder="输入手机号" class="layui-input js-tel">
                </div>
            </div> 
            <div class="layui-form-item">
                <label class="layui-form-label">短信验证码</label>
                <div class="layui-input-block">
                    <input type="number" name="schoolname" lay-verify="schoolname" autocomplete="off" placeholder="短信验证码" class="layui-input js-code" style='width:500px;display: inline-block;float:left;'>
                    <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid js-send" id="btnSendCode" style='background-color:#3475c3;border-radius: 5px;border:none;color:#fff;width:160px;display: inline-block;float:left;margin-left:20px;'>获取验证码</button>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">输入新密码</label>
                <div class="layui-input-block">
                    <input type="password" name="schoolname" lay-verify="schoolname" autocomplete="off" placeholder="请输入新的支付密码" class="layui-input mima1">
                </div>
            </div> 
            

        </div>
            
            

        <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
                <div class="layui-footer" style="left: 0;">
                    <!-- <button class="layui-btn" id="forget">保存</button> -->
                    <button class="layui-btn submit">保存</button>
                </div>
            </div>
        </div>
        </div>        
      </div>
    </div>
   
</div>

<input type="hidden" class="js_is_forget" value="0">


<script src="{{asset('/layuiadmin/layui/layui.js')}}"></script> 
<script type="text/javascript" src="{{asset('/school/js/jsencrypt.min.js')}}"></script>
<script src="{{asset('/layuiadmin/jquery.min.js')}}"></script>
<script>
    var token = localStorage.getItem("Publictoken");
    

    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        formSelects: 'formSelects'
    }).use(['index', 'table','form','upload'], function(){
        var $ = layui.$   
            admin = layui.admin         
            ,table = layui.table
            ,element = layui.element
            ,upload = layui.upload
            ,form = layui.form;

            element.render();
        // 未登录,跳转登录页面
        $(document).ready(function(){        
            if(token==null){
                window.location.href="{{url('/user/login')}}"; 
            }

            
        });        

       

        //发送验证码
        var InterValObj; //timer变量，控制时间
        var count = 60; //间隔函数，1秒执行
        var curCount;//当前剩余秒数

        $('#btnSendCode').click(function(){
          var encrypt = new JSEncrypt();
          var phone=$('.js-tel').val();
          encrypt.setPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4COVutRbOUfQNjvVOzwK49NzHIPRwwksnJ6QtdHwGmdUZiT2HZxVwfotcOjA5aY16D/2Ahq3gLH4yu2y42dS0lfeBMqUcm+bY7aZ54wClm75RI90uc54F8IgMkNz8J/VS9LYI/B4uHVsc+4KK4Ycr8S8O004ExtvQqu2QCl7Aai/WC4URIdCyNm8La2axoA1jjj3SzpytLvP6Z/iHSlx37Y9AMR0V94R13v4BFlMQDG+2REVJsk6LCyzHQfUvJlnsyKey0n/v8DLC070lQzLPYV0jsiit2AUkyURRLxEaZm2C0YYhfrGjl+x8n/kDteZbDVcyn7UsEdSicijv9DXkQIDAQAB");
          var data = encrypt.encrypt('type=editpassword&info=2&phone='+phone);
          

          curCount = count;
          //设置button效果，开始计时
          $("#btnSendCode").attr("disabled", "true");
          $("#btnSendCode").val(curCount+'(s)');
          InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次
          //向后台发送处理数据
          $.post("{{url('/api/Sms/send')}}",
              {
                  sign:data 
              },
              function (res){
                  console.log(res);
                  if(res.status==1){
                      layer.msg(res.message);
                      $("#btnSendCode").attr("disabled", "true");
                      $("#btnSendCode").html(curCount+'(s)');
                      window.clearInterval(InterValObj);//停止计时器
                      InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次
                  }else{
                      $("#btnSendCode").html("获取验证码");
                      window.clearInterval(InterValObj);//停止计时器
                      $("#btnSendCode").removeAttr("disabled");//启用按钮                    
                      alert(res.message);
                  }
              },'json');
        })

        //timer处理函数
        function SetRemainTime() {
            if (curCount == 0) {
                window.clearInterval(InterValObj);//停止计时器
                $("#btnSendCode").removeAttr("disabled");//启用按钮
                $("#btnSendCode").html("获取验证码");
            }
            else {
                curCount--;
                $("#btnSendCode").html(curCount+'(s)');
            }
        } 

        $('.submit').on('click', function(){   
                        
            var encrypt = new JSEncrypt();
            encrypt.setPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4COVutRbOUfQNjvVOzwK49NzHIPRwwksnJ6QtdHwGmdUZiT2HZxVwfotcOjA5aY16D/2Ahq3gLH4yu2y42dS0lfeBMqUcm+bY7aZ54wClm75RI90uc54F8IgMkNz8J/VS9LYI/B4uHVsc+4KK4Ycr8S8O004ExtvQqu2QCl7Aai/WC4URIdCyNm8La2axoA1jjj3SzpytLvP6Z/iHSlx37Y9AMR0V94R13v4BFlMQDG+2REVJsk6LCyzHQfUvJlnsyKey0n/v8DLC070lQzLPYV0jsiit2AUkyURRLxEaZm2C0YYhfrGjl+x8n/kDteZbDVcyn7UsEdSicijv9DXkQIDAQAB");

            console.log($('.js-code').val())            
            var dataA = encrypt.encrypt('code='+$('.js-code').val());
            var dataB = encrypt.encrypt('code='+$('.js-code').val()+'&new_pay_password='+$('.mima1').val());

            $.post("{{url('/api/merchant/forget_pay_password')}}",
            {
                token:token,
                sign:dataA

            },function(res){
                console.log(res);
                if(res.status==1){
                    $.post("{{url('/api/merchant/forget_pay_password')}}",
                    {
                        token:token,
                        sign:dataB
                    },function(res){
                        console.log(res);
                        if(res.status==1){
                            layer.msg(res.message, {
                                offset: '50px'
                                ,icon: 1
                                ,time: 3000
                            });
                        }else{
                            layer.msg(res.message, {
                                offset: '50px'
                                ,icon: 2
                                ,time: 3000
                            });
                        }
                    },"json");
                }else{
                    layer.msg(res.message, {
                        offset: '50px'
                        ,icon: 2
                        ,time: 3000
                    });
                }
            },"json");
            
        });
       
        //双击重置支付密码
        $(".layui-card-header").dblclick(function(){
            let encrypt = new JSEncrypt();
            encrypt.setPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4COVutRbOUfQNjvVOzwK49NzHIPRwwksnJ6QtdHwGmdUZiT2HZxVwfotcOjA5aY16D/2Ahq3gLH4yu2y42dS0lfeBMqUcm+bY7aZ54wClm75RI90uc54F8IgMkNz8J/VS9LYI/B4uHVsc+4KK4Ycr8S8O004ExtvQqu2QCl7Aai/WC4URIdCyNm8La2axoA1jjj3SzpytLvP6Z/iHSlx37Y9AMR0V94R13v4BFlMQDG+2REVJsk6LCyzHQfUvJlnsyKey0n/v8DLC070lQzLPYV0jsiit2AUkyURRLxEaZm2C0YYhfrGjl+x8n/kDteZbDVcyn7UsEdSicijv9DXkQIDAQAB");
            let newPayPass = '000000'
            let data1 = encrypt.encrypt('&new_pay_password='+newPayPass);
            layer.confirm('确认重置该账户的退款密码为000000吗?',{icon: 2}, function(index){
                $.post("{{url('/api/merchant/edit_pay_password')}}",
                {
                    token:token,
                    sign:data1
                },function(res){
                    if(res.status==1){
                        layer.msg(res.message, {
                            offset: '50px'
                            ,icon: 1
                            ,time: 2000
                        });
                    }else{
                        layer.msg(res.message, {
                            offset: '50px'
                            ,icon: 2
                            ,time: 3000
                        });
                    }
                },"json");
            });
        });

        

        


    });
</script>
</body>
</html>
